package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.DictConstant;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.otd.pojo.OtdOrderScheduleQueryVO;
import com.yunxi.otd.pojo.OtdOrderSoEditVO;
import com.yunxi.otd.service.OtdOrderSoDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * SO订单 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-07-05
 */
@RestController
@RequestMapping("/admin/otd/so")
@Api(tags = "OTD:ORDERSO", description = "SO订单接口")
public class OtdOrderSoController {

    private static final Logger logger = LoggerFactory.getLogger(OtdOrderSoController.class);

    @Autowired
    OtdOrderSoDubboService otdOrderSoDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "日排程查询")
    public ApiResult page(OtdOrderScheduleQueryVO queryVO) {
        if(StringUtils.isEmpty(queryVO.getYearMonth())){
            return ResponseUtil.fail(-1, "年月不能为空");
        }
        logger.info("日排程查询...");
        //国内海外商品车排产
        queryVO.setOrderType(DictConstant.OTD_ORDER_TYPE_INVE + "," + DictConstant.OTD_ORDER_TYPE_EXVE);
        return ResponseUtil.ok(otdOrderSoDubboService.findSoSchedule(queryVO));
    }

    @PostMapping("/edit")
    public ApiResult edit(@RequestBody OtdOrderSoEditVO editVO) {
        return otdOrderSoDubboService.updateSoOrderNum(editVO);
    }

}
